package com.example.administrator.mobvista2;

import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.mintegral.msdk.MIntegralSDK;
import com.mintegral.msdk.interstitialvideo.out.InterstitialVideoListener;
import com.mintegral.msdk.interstitialvideo.out.MTGInterstitialVideoHandler;
import com.mintegral.msdk.out.MIntegralSDKFactory;

import java.util.Map;

public class MainActivity extends AppCompatActivity
{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initHandler();
        }
    private void initHandler() {

        final String TAG = "InterVideoActivity";
        final MTGInterstitialVideoHandler mMtgInterstitalVideoHandler;
        final String mRewardUnitId = "109652";
        final  String appId = "114952";
        final String appKey ="87a1920057150ad2a12b520f20da756a";
        final  ProgressDialog pd;

         MIntegralSDK sdk = MIntegralSDKFactory.getMIntegralSDK();
        Map<String, String> map = sdk.getMTGConfigurationMap(appId, appKey);
        sdk.init(map, this);
        pd=new ProgressDialog(this);
        pd.setMessage("游戏启动中...");
        pd.show();

        try {
            mMtgInterstitalVideoHandler = new com.mintegral.msdk.interstitialvideo.out.MTGInterstitialVideoHandler(this, mRewardUnitId);
            mMtgInterstitalVideoHandler.setInterstitialVideoListener(new InterstitialVideoListener() {

                @Override
                public void onLoadSuccess(String unitId) {
                    Log.e(TAG, "onLoadSuccess:"+Thread.currentThread());
                }
                @Override
                public void onVideoLoadSuccess(String unitId) {
                    Log.e(TAG, "onVideoLoadSuccess:"+Thread.currentThread());
                    mMtgInterstitalVideoHandler.show();
                    pd.dismiss();
                }

                @Override
                public void onVideoLoadFail(String errorMsg) {
                    Log.e(TAG, "onVideoLoadFail errorMsg:"+errorMsg);
                    pd.dismiss();
                }

                @Override
                public void onShowFail(String errorMsg) {
                    Log.e(TAG, "onShowFail=" + errorMsg);
                    pd.dismiss();
                }

                @Override
                public void onAdShow() {
                    Log.e(TAG, "onAdShow");
                }

                @Override
                public void onAdClose(boolean isCompleteView) {
                    Log.e(TAG, "onAdClose rewardinfo :" +  "isCompleteView："+isCompleteView);
                }

                @Override
                public void onVideoAdClicked(String unitId) {
                    Log.e(TAG, "onVideoAdClicked");
                }

                @Override
                public void onVideoComplete(String unitId) {
                    Log.e(TAG,"onVideoComplete");
                }

                @Override
                public void onEndcardShow(String unitId) {
                    Log.e(TAG,"onEndcardShow");
                }

            });

            if (mMtgInterstitalVideoHandler != null) {
                mMtgInterstitalVideoHandler.load();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
